from flask import Flask, jsonify
import os
import config

app = Flask(__name__)


@app.route("/api/meta/", methods=["GET"])
def get_dir():
    list_dict_dir = []
    for file_name in os.listdir(config.path_dir):
        type_file = ""  # в linux все есть файл
        file_name_dir = f"{config.path_dir}/{file_name}"
        is_dir = os.path.isdir(file_name_dir)
        if is_dir:
            type_file = "folder"
        else:
            type_file = "file"
        time_second = int(os.path.getctime(file_name_dir))
        dict_dir = {"name": file_name, "type": type_file, "time": time_second}
        list_dict_dir.append(dict_dir)
        type_file = ""
    return jsonify({"data": list_dict_dir})


if __name__ == "__main__":
    app.run(host="0.0.0.0")
